<?php

namespace app\api\controller;

use app\services\RewardService;
use app\services\TokenService;
use support\Db;
use support\Request;

class RewardController
{
    public function add(Request $request)
    {
        $videoId = $request->post('video_id', 0);
        $money = $request->post('money', 0);
        try {
            Db::beginTransaction();

            RewardService::add($videoId, $money);
            Db::commit();
            return ok_rsp('成功');
        } catch (\Exception $e) {
            Db::rollBack();
            return err_rsp($e->getMessage());
        }
    }

    public function lst(Request $request)
    {
        $page = $request->post('page', 1);
        $length = $request->post('length', 10);
        try {
            $data = RewardService::list($page, $length);
            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            echo $e->getMessage() . $e->getTraceAsString();
            return err_rsp($e->getMessage());
        }
    }
}